<?php

/**
 * This is the model class for table "tbl_admin".
 *
 * The followings are the available columns in table 'tbl_admin':
 * @property integer $id
 * @property string $role
 * @property string $email
 * @property string $username
 * @property string $password
 * @property string $fullname
 * @property string $avatar
 * @property string $phone
 * @property string $dob
 * @property string $address
 * @property integer $gender
 * @property integer $status
 * @property integer $login_type
 * @property string $last_visited
 * @property integer $user_created
 * @property string $created_at
 * @property integer $user_updated
 * @property string $updated_at
 *
 * The followings are the available model relations:
 * @property Item[] $itemCreated
 * @property Item[] $itemUpdated
 * @property Style[] $styleCreated
 * @property Style[] $styleUpdated
 */
class Admin extends CActiveRecord {

    const ACCOUNT_LOCKED = 0;
    const OFFLINE = 0;
    const ONLINE_PC = 1;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Admin the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'tbl_admin';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('role, email, username, password, fullname, phone, address, gender, created_at', 'required'),
            array('gender, status, login_type, user_created, user_updated', 'numerical', 'integerOnly' => true),
            array('role, fullname, avatar', 'length', 'max' => 100),
            array('email, username, password', 'length', 'max' => 40),
            array('phone', 'length', 'max' => 11),
            array('address', 'length', 'max' => 200),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, role, email, username, password, fullname, avatar, phone, dob, address, gender, status, login_type, last_visited, user_created, created_at, user_updated, updated_at', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'itemCreated' => array(self::HAS_MANY, 'Item', 'user_created'),
            'itemUpdated' => array(self::HAS_MANY, 'Item', 'user_updated'),
            'styleCreated' => array(self::HAS_MANY, 'Style', 'user_updated'),
            'styleUpdated' => array(self::HAS_MANY, 'Style', 'user_created'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'role' => 'Quyền',
            'email' => 'Email',
            'username' => 'Tên tài khoản',
            'password' => 'Mật khẩu',
            'fullname' => 'Họ và tên',
            'avatar' => 'Avatar',
            'phone' => 'Số điện thoại',
            'dob' => 'Ngày sinh',
            'address' => 'Địa chỉ',
            'gender' => 'Giới tính',
            'status' => 'Trạng thái',
            'login_type' => 'Login Type',
            'last_visited' => 'Last Visited',
            'user_created' => 'Người tạo',
            'created_at' => 'Ngày tạo',
            'user_updated' => 'Người cập nhật',
            'updated_at' => 'Ngày cập nhật',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('role', $this->role, true);
        $criteria->compare('email', $this->email, true);
        $criteria->compare('username', $this->username, true);
        $criteria->compare('password', $this->password, true);
        $criteria->compare('fullname', $this->fullname, true);
        $criteria->compare('avatar', $this->avatar, true);
        $criteria->compare('phone', $this->phone, true);
        $criteria->compare('dob', $this->dob, true);
        $criteria->compare('address', $this->address, true);
        $criteria->compare('gender', $this->gender);
        $criteria->compare('status', $this->status);
        $criteria->compare('login_type', $this->login_type);
        $criteria->compare('last_visited', $this->last_visited, true);
        $criteria->compare('user_created', $this->user_created);
        $criteria->compare('created_at', $this->created_at, true);
        $criteria->compare('user_updated', $this->user_updated);
        $criteria->compare('updated_at', $this->updated_at, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}